package logic

import (
	"B/models/mysql"
	"context"

	"B/internal/svc"
	"B/shenzhousrv"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *shenzhousrv.OrderListRequest) (*shenzhousrv.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	var orderList []mysql.Order
	mysql.DB.Debug().Find(&orderList)
	var lists []*shenzhousrv.OrderList
	for _, v := range orderList {
		lists = append(lists, &shenzhousrv.OrderList{
			UserId:    int64(v.UserId),
			OrderId:   int64(v.ID),
			Numbering: v.Numbering,
			Total:     float32(v.Total),
			Status:    v.Status,
		})
	}
	return &shenzhousrv.OrderListResponse{
		List: lists,
	}, nil
}
